from fastapi import APIRouter, HTTPException
from api.dep import auth_dep, uow_dep
from api.dto import generate_sqlalchemy_dto, StateDTO

router = APIRouter(prefix="/states", tags=["states"])


@router.get("/get_state/{state_id}")
async def get_state(state_id: int, token=auth_dep, uow=uow_dep):
    await uow.users.check_auth_and_get(token)

    state = await uow.states.select_by_id(state_id)

    if state is None:
        raise HTTPException(status_code=404,
                            detail="Государство не найдено")

    return generate_sqlalchemy_dto(StateDTO, state)
